package teaching.io.advance;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

import teaching.io.entity.Student;

/**
 * 对象序列化示例。
 * 
 * @author deng.zhao
 *
 */
public class ObjectOutputStreamExample {

	public static void main(String[] args) {
		List<Student> students = new ArrayList<Student>();		
		students.add(new Student("0001", "张三", new GregorianCalendar(1997, Calendar.JANUARY, 28).getTime(), 'M'));
		students.add(new Student("0002", "李四", new GregorianCalendar(1996, Calendar.DECEMBER, 7).getTime(), 'F'));
		students.add(new Student("0003", "王五", new GregorianCalendar(1997, Calendar.DECEMBER, 20).getTime(), 'F'));
		
		try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("d:/stu.dat"));) {
			oos.writeObject(students);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println("OK!");
	}
}
